package com.woniuxy.cloud.carl.marketing.app.apiImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.cloud.Aspect.log.Log;
import com.woniuxy.cloud.carl.marketing.client.ServiceCouponClient;
import com.woniuxy.cloud.carl.marketing.client.param.AddServiceParam;
import com.woniuxy.cloud.carl.marketing.client.param.GetCouponParam;
import com.woniuxy.cloud.carl.marketing.infra.model.Coupon;
import com.woniuxy.cloud.carl.marketing.infra.model.ServiceCoupon;
import com.woniuxy.cloud.carl.marketing.service.CouponService;
import com.woniuxy.cloud.carl.marketing.service.ServiceCouponService;
import com.woniuxy.result.Result;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
public class ServiceCouponAPIImpl implements ServiceCouponClient {
    @Autowired
    private ServiceCouponService serviceCouponService;
    @Autowired
    private CouponService couponService;
    @Override
    @Log("添加服务优惠券")
    public Result addServiceCoupon(AddServiceParam param) {
        return serviceCouponService.addServiceCoupon(param);
    }


    @Override
    @Log("查询服务优惠券")
    public Result<Page<ServiceCoupon>> getServiceCoupon(GetCouponParam param) {
        if (param.getPageNum()==null||param.getPageNum()<1)
            param.setPageNum(1);
        if (param.getPageSize()==null||param.getPageSize()<1)
            param.setPageSize(8);
        Result<Page<ServiceCoupon>> coupon = serviceCouponService.getCoupon(param);
        return coupon;
    }

    @Override
    public Result useServiceCoupon(Long storeId, Long userId, Long couponId) {

        return serviceCouponService.useServiceCoupon(storeId, couponId.toString());
    }


}
